package com.ruoyi.dataBase.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import cn.dev33.satoken.annotation.SaMode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.dataBase.domain.vo.IndustrialTransportProjectVo;
import com.ruoyi.dataBase.domain.bo.IndustrialTransportProjectBo;
import com.ruoyi.dataBase.service.IIndustrialTransportProjectService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 交通物流项目
 *
 * @author yangzhen
 * @date 2025-11-10
 */
@Tag(name = "交通物流项目", description = "交通物流项目相关接口")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/dataBase/transportProject")
public class IndustrialTransportProjectController extends BaseController {

    private final IIndustrialTransportProjectService iIndustrialTransportProjectService;

    /**
     * 查询交通物流项目列表
     */
    @Operation(summary = "查询交通物流项目列表", description = "用于查询交通物流项目列表")
    @SaCheckPermission("dataBase:transportProject:list")
    @GetMapping("/list")
    public TableDataInfo<IndustrialTransportProjectVo> list(IndustrialTransportProjectBo bo, PageQuery pageQuery) {
        return iIndustrialTransportProjectService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出交通物流项目列表
     */
    @Operation(summary = "导出交通物流项目列表", description = "用于导出交通物流项目列表")
    @SaCheckPermission("dataBase:transportProject:export")
    @Log(title = "交通物流项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(IndustrialTransportProjectBo bo, HttpServletResponse response) {
        List<IndustrialTransportProjectVo> list = iIndustrialTransportProjectService.queryList(bo);
        ExcelUtil.exportExcel(list, "交通物流项目", IndustrialTransportProjectVo.class, response);
    }

    /**
     * 获取交通物流项目详细信息
     *
     * @param id 主键
     */
    @Operation(summary = "获取交通物流项目详细信息", description = "用于获取交通物流项目详细信息")
    @SaCheckPermission("dataBase:transportProject:query")
    @GetMapping("/{id}")
    public R<IndustrialTransportProjectVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iIndustrialTransportProjectService.queryById(id));
    }

    /**
     * 新增交通物流项目
     */
    @Operation(summary = "新增交通物流项目", description = "用于新增交通物流项目")
    @SaCheckPermission("dataBase:transportProject:add")
    @Log(title = "交通物流项目", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody IndustrialTransportProjectBo bo) {
        return toAjax(iIndustrialTransportProjectService.insertByBo(bo));
    }

    /**
     * 修改交通物流项目
     */
    @Operation(summary = "修改交通物流项目", description = "用于修改交通物流项目")
    @SaCheckPermission(value = {"dataBase:transportProject:edit", "dataBase:transportProject:review"}, mode = SaMode.OR)
    @Log(title = "交通物流项目", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody IndustrialTransportProjectBo bo) {
        return toAjax(iIndustrialTransportProjectService.updateByBo(bo));
    }

    /**
     * 删除交通物流项目
     *
     * @param ids 主键串
     */
    @Operation(summary = "删除交通物流项目", description = "用于删除交通物流项目")
    @SaCheckPermission("dataBase:transportProject:remove")
    @Log(title = "交通物流项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iIndustrialTransportProjectService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
